package com.example.demo.web;

import com.example.demo.config.globalexception.SystemRuntimeException;
import com.example.demo.config.response.ResponseResult;
import com.example.demo.config.session.LoginUser;
import com.example.demo.config.session.PassToken;
import com.example.demo.model.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author
 * 全局异常测试
 */
@Api(tags = "全局异常测试")
@RestController
@RequestMapping("/global/exception")
@Slf4j
public class GlobalExceptionController {

    /**
     * 比较字符串
     */
    private static final String COMPARE_STR = "topCombine";

    @GetMapping("/systemRuntimeException")
    @ApiOperation(value = "系统自定义异常")
    public String systemRuntimeException(){
        throw new SystemRuntimeException("自定义系统异常");
    }

    @GetMapping("/nullPointerException")
    @ApiOperation(value = "空指针异常")
    public void nullPointerException(){
        String str = null;
        if(str.equals(COMPARE_STR)){
            log.info("str:{}", str);
        }
    }

    @GetMapping("/runtimeException")
    @ApiOperation(value = "运行时异常")
    public void runtimeException(@LoginUser User user){
        int a = 1;
        System.out.println(a / 0);
    }

}
